package com.general.adminserver.service;

import com.general.adminserver.model.UserInfoBo;
import com.general.common.utils.JsonMapper;
import com.general.persistent.mapper.UserMapper;
import com.general.persistent.po.UserInfoPo;
import org.codehaus.jackson.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Songjiuhua
 * @date 2018-01-30
 */
@Service
public class TestService {

    @Autowired
    private UserMapper userMapper;

    public String sayHello(String name){
        System.out.println("Hello " + name + " !");
        return "Hello " + name + " !";
    }

    public List<UserInfoBo> queryUserInfo(){
        List<UserInfoBo> userInfoBoList = new ArrayList<>();
        try{
            List<UserInfoPo> userInfoPoList = userMapper.queryUserInfo();
            if (!CollectionUtils.isEmpty(userInfoPoList)){
                userInfoBoList = JsonMapper.getInstance().readValue(JsonMapper.convertObjectToJson(userInfoPoList), new TypeReference<List<UserInfoBo>>(){});
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return userInfoBoList;
    }

}
